import {
  Navigate,
  createBrowserRouter,
} from 'react-router'
import type { RouteObject } from 'react-router'

import { lazy, Suspense } from 'react'

import Loading from '@/views/common/loading/loading.tsx'

import NotFound from '@/views/common/error/404.tsx'

import Home from '@/views/home/Home.tsx'

// 自定义懒加载函数
const lazyLoad = (factory: () => Promise<any>) => {
  const Module = lazy(factory)
  return (
    <Suspense fallback={<Loading />}>
      <Module />
    </Suspense>
  )
}

const AllRoutes: RouteObject[] = [
  {
    path: '/',
    element: <Home />,
  },
  {
    path: '/error',
    element: <NotFound />,
  },
]

export { AllRoutes, lazyLoad }
